/*
 * @lc app=leetcode.cn id=1422 lang=typescript
 *
 * [1422] 分割字符串的最大得分
 */

// @lc code=start
function maxScore(s: string): number {
    let final =
        (s[0] === "0" ? 1 : 0) +
        s
            .slice(1)
            .split("")
            .filter((i) => i === "1").length;
    let max = final;
    for (let i = 1; i < s.length - 1; i++) {
        const element = s[i];
        if (element === "0") {
            final += 1;
        } else {
            final -= 1;
        }
        max = Math.max(max, final);
    }
    return max;
}
// @lc code=end
